﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace DATN.Account
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        SqlConnection cnn;
        SqlCommand cmd;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["Us_Id"] != null)
                {
                    //Bind data vào GridView
                    //BindData();
                }
                else
                {
                    Response.Redirect("../Account/Login.aspx");
                }
                Validate();
            }
        }

        //Check Old Password
        int ChUsPas;
        protected int check_OldPass(int us_id, string password)
        {
            ChUsPas = 0;
            try
            {
                string cnnString = ConfigurationManager.ConnectionStrings["DATNconnection"].ConnectionString;
                cnn = new SqlConnection(cnnString);
                cnn.Open();

                String queryString = "SELECT Count(*) FROM Users WHERE Us_Id= @Us_Id AND Password =@Password ";
                cmd = new SqlCommand(queryString, cnn);
                cmd.Parameters.Add("@Us_Id", SqlDbType.Int);
                cmd.Parameters["@Us_Id"].Value = us_id;

                cmd.Parameters.Add("@Password", SqlDbType.VarChar);
                cmd.Parameters["@Password"].Value = Encrypt.EncryptText(password, true);

                ChUsPas = Convert.ToInt32(cmd.ExecuteScalar().ToString());

            }
            catch (Exception ex)
            {
                Response.Write(" Lỗi ở Check UserName: " + ex);
            }
            return ChUsPas;
        }

        //Update New Password

        protected void bt_ChangePass_Click(object sender, EventArgs e)
        {
             int us_id = Convert.ToInt16(Session["Us_Id"].ToString());

            // check_OldPass(us_id, )
        }
    }
}